a11y: Avoid out-of-bounds access
authorMatthias Clasen <mclasen@redhat.com>
Thu, 4 Feb 2021 05:34:05 +0000 (00:34 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 4 Feb 2021 05:34:05 +0000 (00:34 -0500)
Don't use the index before we've checked its good.

Pointed out in https://www.viva64.com/en/b/0793/

gtk/a11y/gtkatspiaction.c

index fb39abf8d570991e9d764d9ed544d9a74c311f89..d31cda147b0df6746c1f916251e989a95dac72ec 100644 (file)
@@ -68,10 +68,8 @@ action_handle_method (GtkAtSpiContext        *self,
 
       g_variant_get (parameters, "(i)", &idx);
 
-      const Action *action = &actions[idx];
-
       if (idx >= 0 && idx < n_actions)
-        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", action->name));
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", actions[idx].name));
       else
         g_dbus_method_invocation_return_error (invocation,
                                                G_IO_ERROR,
@@ -129,10 +127,8 @@ action_handle_method (GtkAtSpiContext        *self,
 
       g_variant_get (parameters, "(i)", &idx);
 
-      const Action *action = &actions[idx];
-
       if (idx >= 0 && idx < n_actions)
-        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", action->keybinding));
+        g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", actions[idx].keybinding));
       else
         g_dbus_method_invocation_return_error (invocation,
                                                G_IO_ERROR,